<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Daftar_objek_wisata extends CI_Model {

    var $output_table;
    
    function __construct()
    {
        parent::__construct();
        $this->load->database();
        $this->load->library('table');
        $this->load->helper(array('text'));
    }
	
	private function make_query($fields='', $table='', $where=array(),$limit=Null, $offset='', $order=array('field'=>Null,'sort'=>'ASC'))
	{
		$this->db->select($fields);
		if( ! is_null($order['field']))
		{
		  $this->db->order_by($order['field'], $order['sort']);
		}
		return $this->db->get_where($table, $where, $limit, $offset);
	}
	
	public function get_daftar_objek($limit, $offset='',$order = array('field'=>'tgl_objek_wisata', 'sort'=>'DESC'))
	{
		$query = $this->make_query('id_objek_wisata,nama_objek_wisata,nama_kabupaten,
		tgl_objek_wisata,deskripsi_objek_wisata,link_gambar_objek_wisata, hits',
		'objek_wisata',array(),$limit,$offset,$order);
        if($query->num_rows() > 0)
		{
			foreach($query->result() as $value)
			{	
				
				$tmpl = array('table_open'=> '<table border="0">');
				$this->table->set_template($tmpl);
				$this->table->add_row('<h2 align="left" class="post_header">'.strtoupper($value->nama_objek_wisata).'</h2>');
				$this->table->add_row('<p align="center"><img src="http://localhost/wisataku2'.$value->link_gambar_objek_wisata.'"/></p>');
				$this->table->add_row('<p align="justify">'.ascii_to_entities(word_limiter($value->deskripsi_objek_wisata,50)).' '.anchor('objek_wisata/detail/'.$value->id_objek_wisata,
										  'read more...').'</p>');
				$this->output_table .= $this->table->generate();
				$this->output_table .= '<br />';
				$this->table->clear();
			}
			return $this->output_table;
		}
		else
		{
			return FALSE;
		}
	}
	
	public function jumlah_objek_wisata($table = '')
	{
		return $this->db->count_all($table);
	}
}
